$(document).ajaxSend(function(event,xhr,options){
    xhr.setRequestHeader("user_token", localStorage.getItem("userToken"));
});
$(document).ajaxError(function(event,xhr,options,exc){
    if(xhr.status==401){
        alert("用户未登录，请先进行登录");
        location.href = "blog_login.html";
    }
})

function getUserInfo(url) {
    $.ajax({
        type: "get",
        url: url,
        success: function(result) {
            if(result != null && result.code == "SUCCESS" && result.data != null) {
                var userInfo = result.data;
                $(".left .card h3").text(userInfo.userName);
                $(".left .card a").attr("href", userInfo.githubUrl);
            }
        } 
    });
}

// 注销，就是直接把令牌删除就可以了
function logout() {
    localStorage.removeItem("loginUserId");
    localStorage.removeItem("userToken");
    alert("注销成功");
    location.href = "blog_login.html";
}